import GameManager from "./GameManager";
import Ending, { End } from "./Gwx/Ending";
import SharkSayManager, { SharkSayType } from "./SharkSayManager";
import Tween_breathe from "./Tween/Tween_breathe";
import WTool from "./WTool";


const { ccclass, property } = cc._decorator;

@ccclass
export default class EndingAnimation extends cc.Component {

    public static PlayEndingAnimation(id: number) {
        GameManager.Instance.GamePause = true;
        if (id == 1) {//胖胖鲨
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局1);
            }, 3)
        }
        if (id == 2) {//口碑太差的饲主
            GameManager.Instance.GamePause = true;
            GameManager.GetNode("room/大胖鲨").active = true;
            GameManager.Instance.scheduleOnce(() => {
                WTool.Tween_By(GameManager.GetNode("room/小鲨鱼"), cc.v2(-300, 0), 1, "", () => {
                    GameManager.GetNode("room/小鲨鱼").scaleX = -GameManager.GetNode("room/小鲨鱼").scaleX;
                    GameManager.Instance.SharkSay([19, 20, 21, 22, 23, 24, 25], () => {
                        GameManager.GetNode("room/大胖鲨").scaleX = -1;
                        WTool.Tween_By(GameManager.GetNode("room/大胖鲨"), cc.v2(650, 0), 1.5, "")
                        WTool.Tween_By(GameManager.GetNode("room/小鲨鱼"), cc.v2(1200, 0), 2, "", () => {
                            EndingAnimation.ShowEnding(End.结局2);
                        })
                    });
                })
            }, 1.5)
            WTool.Tween_By(GameManager.GetNode("room/大胖鲨"), cc.v2(-650, 0), 2, "")
        }

        if (id == 3) {//流浪鲨鱼
            let shark = GameManager.Instance.SharkNode;
            GameManager.Instance.LoadSharkSprite("身体/流浪").then((data: cc.SpriteFrame) => {
                shark.getComponent(cc.Sprite).spriteFrame = data;
                shark.getChildByName("鲨手").active = false;
            });
            GameManager.Instance.LoadSharkSprite("表情/皱眉").then((data: cc.SpriteFrame) => {
                shark.getChildByName("脸").getComponent(cc.Sprite).spriteFrame = data;
            });
            GameManager.Instance.SharkSay(SharkSayManager.GetSharkSayDate(SharkSayType.吊胃口), () => {
                GameManager.Instance.Tantalizeindex++;
                shark.getComponent(Tween_breathe).TweenId.stop();
                shark.scaleX = -GameManager.Instance.SharkNode.scaleX;
                GameManager.Instance.SharkSay(SharkSayManager.GetSharkSayDate(SharkSayType.吊胃口), () => {
                    cc.tween(shark)
                        .delay(0.3)
                        .to(2, { position: cc.v3(shark.x + cc.view.getVisibleSize().width / 2, shark.y) })
                        .call(() => {
                            EndingAnimation.ShowEnding(End.结局3);
                        })
                        .start()
                })
            })
        }
        if (id == 4) {//被视作无用的鲨鱼
            GameManager.GetUINode("黑色遮罩").active = true;
            GameManager.GetNode("room/小鲨鱼").active = false;
            GameManager.GetNode("room/无用的鲨鱼").active = true;
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局4);
            }, 3)
        }
        if (id == 5) {//横纹肌溶解
            GameManager.Instance.SharkNode.getChildByName("印堂发黑").active = false;
            GameManager.Instance.SharkNode.getChildByName("脸").active = false;
            GameManager.Instance.SharkNode.getComponent(Tween_breathe).TweenId.stop();
            GameManager.Instance.LoadSharkSprite("身体/健身死").then((data: cc.SpriteFrame) => {
                GameManager.Instance.SharkNode.getComponent(cc.Sprite).spriteFrame = data;
                GameManager.Instance.SharkNode.setPosition(-40, 20);
            });
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局5);
            }, 2)
        }
        if (id == 6) {//失眠的鲨鱼
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局6);
            }, 7)
        }

        if (id == 7) {//反悔的饲主
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局7);
            }, 2)
        }

        if (id == 8) {//成为养料的鲨鱼
            GameManager.GetUINode("黑色遮罩").active = true;
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局8);
            }, 3)
        }

        if (id == 9) {//破镜难圆
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局9);
            }, 2)
        }

        if (id == 10) {//与你无关的事物
            GameManager.GetUINode("黑色遮罩").active = true;
            GameManager.Instance.scheduleOnce(() => {
                EndingAnimation.ShowEnding(End.结局10);
            }, 2)
        }

        if (id == 11) {//一个人也很自在
            EndingAnimation.ShowEnding(End.结局11);
        }
    }


    //显示对应结局
    public static ShowEnding(end: End) {
        GameManager.Instance.LoadPrefab("Ending", (pre) => {
            let ending = cc.instantiate(pre)
            ending.setParent(GameManager.Instance.UINode);
            ending.getComponent(Ending).Init(end);
        })
    }
}
